package br.ufms.cpcx.iara;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class IARAActivity extends Activity {

	
	// private String url = "https://cloudiara-asousajose.rhcloud.com/iara";
	// private String url ="http://env-3194404.jelastic.websolute.net.br/iara/iara";
	private String url ="http://192.168.0.108:8080/cloudiara/iara";
	private Banco b;

	private static final int sobre = 0;

	// private static final int REMOVE = 1;
	/** Called when the activity is first created. */
	Button btSozinho, btGalera, btEncontro, btSugestao;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tela);
		// listReceitas.setOnItemClickListener(this);

		btSozinho = (Button) findViewById(R.id.btsozinho);
		btEncontro = (Button) findViewById(R.id.btencon);
		btGalera = (Button) findViewById(R.id.btgalera);
		

	}

	
	public void sozinho(View v) {

		// startActivity(new Intent(IARAActivity.this,ListReceitas.class));
		//url = "http://192.168.0.2:8080/ServerIara/iara";
		Log.i("Sozinho", "Entrou");
		ArrayList<NameValuePair> parametrosPost = new ArrayList<NameValuePair>();
		parametrosPost.add(new BasicNameValuePair("acompanhado", "sozinho"));
		String respostaRetornada = null;

		try {
			respostaRetornada = ConexaoHttpClient.executaHttpPost(url,
					parametrosPost);
			String resposta = respostaRetornada.toString();
			Intent intent = new Intent(v.getContext(), MainActivity.class);
			Bundle parametros = new Bundle();
			parametros.putString("paremetro", resposta.replaceAll("\\n", ""));
			intent.putExtras(parametros);
			startActivity(intent);

			

		} catch (Exception erro) {
			Log.i("erro", "erro = " + erro);
			System.out.println(erro);
			Toast.makeText(this, "Erro.: " + erro, Toast.LENGTH_LONG).show();
		}
	}

	public void galera(View v) {
		// TODO Auto-generated method stub
		//url = "http://192.168.0.2:8080/ServerIara/iara";
		Log.i("Galera", "Entrou");
		ArrayList<NameValuePair> parametrosPost = new ArrayList<NameValuePair>();
		parametrosPost.add(new BasicNameValuePair("acompanhado", "TURMA"));
		String respostaRetornada = null;
		try {
			respostaRetornada = ConexaoHttpClient.executaHttpPost(url,
					parametrosPost);
			String resposta = respostaRetornada.toString();
			Intent intent = new Intent(v.getContext(), MainActivity.class);
			Bundle parametros = new Bundle();
			parametros.putString("paremetro", resposta.replaceAll("\\n", ""));
			intent.putExtras(parametros);
			startActivity(intent);

			

		} catch (Exception erro) {
			Log.i("erro", "erro = " + erro);
			System.out.println(erro);
			Toast.makeText(this, "Erro.: " + erro, Toast.LENGTH_LONG).show();
		}

	}
	public void encontro(View v) {
		// TODO Auto-generated method stub
		//url = "http://192.168.0.2:8080/ServerIara/iara";
		Log.i("Galera", "Entrou");
		ArrayList<NameValuePair> parametrosPost = new ArrayList<NameValuePair>();
		parametrosPost
				.add(new BasicNameValuePair("acompanhado", "ACOMPANHADO"));
		String respostaRetornada = null;

		try {
			respostaRetornada = ConexaoHttpClient.executaHttpPost(url,
					parametrosPost);
			String resposta = respostaRetornada.toString();
			Intent intent = new Intent(v.getContext(), MainActivity.class);
			Bundle parametros = new Bundle();
			parametros.putString("paremetro", resposta.replaceAll("\\n", ""));
			intent.putExtras(parametros);
			startActivity(intent);

			

		} catch (Exception erro) {
			Log.i("erro", "erro = " + erro);
			System.out.println(erro);
			Toast.makeText(this, "Erro.: " + erro, Toast.LENGTH_LONG).show();
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);

		MenuItem menuSobre = menu.add(sobre, sobre, 0, "Sobre");
		menuSobre.setShortcut('0', 'f');
		menuSobre.setIcon(android.R.drawable.ic_menu_info_details);

		return super.onCreateOptionsMenu(menu);
	}



	public void mensagemExibir(String titulo, String texto) {
		AlertDialog.Builder mensagem = new AlertDialog.Builder(
				IARAActivity.this);
		mensagem.setTitle(titulo);
		mensagem.setMessage(texto);
		mensagem.setNeutralButton("OK", null);
		mensagem.show();
	}

	private void trace(String msg) {
		final Dialog dialog = new Dialog(this);

		dialog.setTitle("IARA");

		dialog.setContentView(R.layout.dialog);

		dialog.setCancelable(true);

		dialog.show();
	}	

}
